package xyz.cloud.gulimall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import xyz.cloud.gulimall.product.entity.CategoryEntity;
import xyz.cloud.gulimall.product.service.CategoryService;
import xyz.cloud.gulimall.coupon.common.utils.PageUtils;
import xyz.cloud.gulimall.coupon.common.utils.R;



/**
 * 商品三级分类
 *
 * @author Íõ¹ØÁØ
 * @email zx1092771091zx@163.com
 * @date 2020-04-28 22:54:08
 */
@RestController
@RequestMapping("product/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 列表
     */
    @RequestMapping("/list/tree")
//  @RequiresPermissions("product:category:list")
    public R list(@RequestParam Map<String, Object> params){
      List<CategoryEntity> lists= categoryService.listWhitTree();
      redisTemplate.opsForSet().add("1","你好");
        return R.ok().put("data", lists);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{catId}")
//  @RequiresPermissions("product:category:info")
    public R info(@PathVariable("catId") Long catId){
		CategoryEntity category = categoryService.getById(catId);
        return R.ok().put("category", category);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//  @RequiresPermissions("product:category:save")
    public R save(@RequestBody CategoryEntity category){
		categoryService.save(category);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//  @RequiresPermissions("product:category:update")
    public R update(@RequestBody CategoryEntity category){
		categoryService.updateById(category);
        return R.ok();
    }

    /**
     * 批量修改
     * @param category
     * @return
     */
    @RequestMapping("/update/sort")
//  @RequiresPermissions("product:category:update")
    public R updateSort(@RequestBody CategoryEntity[] category){
        //使用 Arrays的asList 把数组转为 集合
       categoryService.updateBatchById(Arrays.asList(category));
        return R.ok();
    }

    /**
     * 删除
     * @RequestBody 获取请求体 必须使用 post 请求
     */
    @RequestMapping("/delete")
//  @RequiresPermissions("product:category:delete")
    public R delete(@RequestBody Long[] catIds){
//		categoryService.removeByIds(Arrays.asList(catIds));
        categoryService.removeMenuByids(Arrays.asList(catIds));
        return R.ok();
    }


    public static void main(String[] args) {
     int [] ints=   {10,1,35,61,89,36,55};
//     int tem=0;
        for (int i = 0; i <ints.length ; i++) {
            for (int j = i+1; j <ints.length ; j++) {
                if (ints[i] > ints[j]) {
//                    System.out.println(ints[i]);
//                    System.out.println(ints[j]);
                 ints[i]= ints[i]+ints[j];
                 ints[j]=ints[i]-ints[j];
                 ints[i]=ints[i]-ints[j];
//                    tem = ints[i];
//                    ints[i]=ints[j];
//                    ints[j]=tem;
                }
            }

        }
        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }

    }



}
